<?php

/*

Process Fishing for Wild Pets (fishing_for_pets.pro.php)

*/
ob_start();
include "global.inc.php";

$findfish = fetch("SELECT * FROM fish_pets2 WHERE userid = '$userid' AND game = '$game'");
$findfishForPetRow = fetch("SELECT * FROM fish_pets_arrays WHERE game = '$game'");

if (!$findfish[id])
{
	die(header(error("fish_for_pets.php?game=$game","You are not fishing right now.")));
}

if ($findfish[found])
{
	die(header(error("fish_for_pets.php?game=$game","You cannot fish until you have finished with what you found (pet, items, nets, etc.)")));
}

if ($act == "move")
{
	if ($move == "up")
	{
		$movey = $findfish[y_cord];
		$movex = $findfish[x_cord] - 1;
	}
	if ($move == "down")
	{
		$movey = $findfish[y_cord];
		$movex = $findfish[x_cord] + 1;
	}
	if ($move == "left")
	{
		$movey = $findfish[y_cord] - 1;
		$movex = $findfish[x_cord];
	}
	if ($move == "right")
	{
		$movey = $findfish[y_cord] + 1;
		$movex = $findfish[x_cord];
	}
	if (($movey < 1) OR ($movey > 8) OR ($movex < 1) OR ($movex > 8))
	{
		die(header(error("fishing_for_pets.php?game=$game","You cannot move past the edge of the map.")));
	}
	$cord = "$movex$movey";
	if (
	($cord == "11") OR
	($cord == "12") OR
	($cord == "13") OR
	($cord == "14") OR
	($cord == "15") OR
	($cord == "16") OR
	($cord == "17") OR
	($cord == "18") OR
	($cord == "21") OR
	($cord == "28") OR
	($cord == "31") OR
	($cord == "38") OR
	($cord == "41") OR
	($cord == "48") OR
	($cord == "51") OR
	($cord == "58") OR
	($cord == "61") OR
	($cord == "68") OR
	($cord == "71") OR
	($cord == "78") OR
	($cord == "81") OR
	($cord == "82") OR
	($cord == "83") OR
	($cord == "84") OR
	($cord == "85") OR
	($cord == "86") OR
	($cord == "87") OR
	($cord == "52") OR
	($cord == "53") OR
	($cord == "54") OR
	($cord == "63") OR
	($cord == "64") OR
	($cord == "65") OR
	($cord == "88")
	)
	{
		die(header(error("fishing_for_pets.php?game=$game","You cannot move into rocks.")));
	}
	mysql_query("UPDATE fish_pets2 SET x_cord=$movex WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET y_cord=$movey WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET direction = '$move' WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET moves_left=$findfish[moves_left]-1 WHERE userid = '$userid' AND game = '$game'");
}

$findPet = rand(1,20);
if ($findPet == 7)
{
	$pets = explode(", ", $findfishForPetRow[pets]);

	$countThePets = count($pets) - 1;
	$randPets = rand(0,$countThePets);
	$randLevel = rand(1,6);

	mysql_query("UPDATE fish_pets2 SET found = 'pet' WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET found_what = '$pets[$randPets]' WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET found_what2=$randLevel WHERE userid = '$userid' AND game = '$game'");
	die(header(error("fish_for_pets.php?game=$game","You have found a wild pet!!!")));
}

$findItem = rand(1,45);
if ($findItem == 20)
{
	$items = explode(", ", $findfishForPetRow[items]);

	$countitems = count($items) - 1;
	$randItem = rand(0,$countitems);

	mysql_query("UPDATE fish_pets2 SET found = 'item' WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET found_what = '$items[$randItem]' WHERE userid = '$userid' AND game = '$game'");
	die(header(error("fish_for_pets.php?game=$game","You have found a $items[$randItem]!")));
}

$findNet = rand(1,35);
if ($findNet == 30)
{
	$nets = array(
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Basic Net",
	"Electric Net",
	"Electric Net",
	"Electric Net",
	"Electric Net",
	"Magic Net",
	"Magic Net",
	"Magic Net",
	"Magic Net"
	);

	$countnets = count($nets) - 1;
	$randNets = rand(0,$countnets);

	mysql_query("UPDATE fish_pets2 SET found = 'net' WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE fish_pets2 SET found_what = '$nets[$randNets]' WHERE userid = '$userid' AND game = '$game'");
	die(header(error("fish_for_pets.php?game=$game","You have found a $items[$randItem]!")));

}

header("Location: fishing_for_pets.php?game=$game");
?>